<template>
  <el-select
    v-model="id"
    size="small"
    style="width: 100%"
    placeholder="请选择职位"
    clearable
    @change="selChange"
  >
    <el-option
      v-for="item in list"
      :key="item.position_code"
      :label="item.name"
      :value="item.position_code"
    />
  </el-select>
</template>

<script>
import { selPosition } from '@/api/organ'

export default {
  name: 'PositionSelect',
  props: {
    value: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      list: [],
      id: null
    }
  },
  watch: {
    'id': {
      handler(n, o) {
      },
      immediate: false
    }
  },
  created() {
    this.selPosition()
  },
  methods: {
    selChange() {
      this.$emit('input', this.id)
    },
    selPosition() {
      selPosition({}).then(response => {
        this.list = response.list
        this.$set(this, 'id', this.value)
      }).catch(err => {
        this.$message.error(err.msg)
      })
    }
  }
}
</script>

<style scoped>
</style>
